package com.dz.content.service;

import com.dz.common.constants.CodeDomain;
import com.dz.content.domain.entity.Content;
import com.dz.content.domain.repository.ContentRepository;
import com.dz.content.domain.vo.ContentResultsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName : ContentServiceImpl
 * @Description :
 * @Author : ming
 * @Date: 2020-12-14 10:52
 **/
@Service
public class ContentServiceImpl implements ContentService{

    @Autowired
    private ContentRepository contentRepository;
    @Override
    public List<ContentResultsVO> findByCategoryId(Long categoryId) {
        List<Content> contentList = contentRepository.findByCategoryIdAndDeleteFlag(categoryId, Integer.valueOf(CodeDomain.DELETE_FLAG_NO.value()));
        List<ContentResultsVO> list = contentList.stream().map(e -> ContentResultsVO.builder()
                .id(e.getId())
                .title(e.getTitle())
                .url(e.getUrl())
                .pic(e.getPic())
                .status(e.getStatus())
                .sortOrder(e.getSortOrder())
                .build()).collect(Collectors.toList());
        return list;
    }
}
